<?php
/**
* 验证
*/
class Validate extends BZ_Controller
{
    public function _init()
    {
        $this->load->helper(array('validation'));
        $this->load->library('sms/sms');
        $this->load->model('user_model', 'user');
        $this->load->model('getpwd_phone_model', 'getpwd_phone');
    }

    /**
     * ajax发送短信
     */
    public function ajaxSendSms()
    {
        $phone = $this->input->post('mobilePhone');
        if (!validateMobilePhone($phone)) {
            $this->jsonMessage('手机号码格式有误');
        }

        $code = mt_rand(100000, 999999);
        $result = $this->getpwd_phone->findByPhone($phone);
        if ( $result->num_rows() > 0 )
        {
            $status = $this->getpwd_phone->updateGetpwdPhone(array('mobile_phone'=>$phone, 'code'=>$code));
        }
        else
        {
            $status = $this->getpwd_phone->insertGetpwdPhone(array('mobile_phone'=>$phone, 'code'=>$code));
        }
        $this->sendToSms($phone, '验证码:'.$code.'，有效期为10分钟。千万不要告诉他人！');
        if ($status)
        {
            $this->jsonMessage('');
        }
        else
        {
            $this->jsonMessage('网络繁忙，请稍后重新获取验证码');
        }
    }
}